package org.uned.agonzalo16.bitacora.web.tag;

import java.io.IOException;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspTagException;
import javax.servlet.jsp.tagext.TagSupport;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Configurable;
import org.uned.agonzalo16.bitacora.dao.CommentDao;
import org.uned.agonzalo16.bitacora.domain.Article;

@Configurable
@SuppressWarnings("serial")
public class CommentsNumberByArticleTag extends TagSupport {

	private transient Article article;

	@Autowired
	private transient CommentDao commentDao;

	public void setArticle(Article article) {
		this.article = article;
	}

	@Override
	public int doStartTag() throws JspException {

		try {
			pageContext.getOut().print(commentDao.countByArticle(article));
		} catch (IOException ioe) {
			throw new JspTagException(ioe.toString(), ioe);
		}
		return SKIP_BODY;
	}
}
